package com.woniu.liuzhougov.relatedinformation.controller.impl;

import com.woniu.liuzhougov.businessproject.vo.BusinessProjectUploadVO;
import com.woniu.liuzhougov.businessproject.vo.Result;
import com.woniu.liuzhougov.fileManage.constant.SysConstant;
import com.woniu.liuzhougov.relatedinformation.controller.AbstractRelatedInformationController;
import com.woniu.liuzhougov.relatedinformation.controller.RelatedInformationController;
import com.woniu.liuzhougov.relatedinformation.pojo.GoodEnterprise;
import com.woniu.liuzhougov.relatedinformation.pojo.RelatedInformation;
import com.woniu.liuzhougov.relatedinformation.service.RelatedInformationService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.List;

/**
 * @Description: 名优企业库控制层
 * @author: Chris
 * @createDate: 2019/4/23 0023
 * @version: 1.0
 */
@Controller
@RequestMapping("/goodEnterprise")
public class GoodEnterpriseController extends AbstractRelatedInformationController<GoodEnterprise> implements RelatedInformationController<GoodEnterprise>{

    @Resource(name = "goodEnterpriseService")
    private RelatedInformationService<GoodEnterprise> goodEnterpriseService;

    /**
     * 展示主页面
     * @return:所有企业名单
     */
    @RequestMapping("/list")
    @ResponseBody
    @RequiresPermissions(value = "goodEnterprise_listGoodenterprises")
    public Result list(){
        return parentList(goodEnterpriseService);
    }

    /**
     * 查询企业
     * @param :企业名
     * @return :符合条件的企业
     */
    @RequestMapping("/search")
    @ResponseBody
    @RequiresPermissions(value = "goodEnterprise_searchGoodenterprise")
    public Result search(String name){
        return parentSearch(goodEnterpriseService,name);
    }

    /**
     * 删除企业
     * @param: deletelist要删除的id数组
     * @return: 操作结果
     */
    @RequestMapping("/delete")
    @ResponseBody
    @RequiresPermissions(value = "goodEnterprise_deleteGoodenterprise")
    public Result delete(@RequestParam(value="deletelist[]")Integer[] deletelist){
        return parentDelete(goodEnterpriseService,deletelist);
    }

    /**
     * 添加企业
     * @param: 企业
     * @return: 响应内容
     */
    @RequestMapping("/add")
    @ResponseBody
    @RequiresPermissions(value = "goodEnterprise_addGoodenterprise")
    public Result add(GoodEnterprise goodEnterprise){
        return parentAdd(goodEnterpriseService,goodEnterprise);
    }

    /**
     * 更新企业信息
     * @param:企业
     * @return:处理代码
     */
    @RequestMapping("/update")
    @ResponseBody
    @RequiresPermissions(value = "goodEnterprise_updateGoodenterprise")
    public Result update(GoodEnterprise goodEnterprise){
        return parentUpdate(goodEnterpriseService,goodEnterprise);
    }

    /**
     * 初始化修改表单
     * @param：需要初始化的对象id
     * @return:初始化信息
     */
    @RequestMapping("/initForm")
    @ResponseBody
    @RequiresPermissions(value = "goodEnterprise_updateGoodenterprise")
    public Result initForm(Integer enterpriceId){
        return parentInitForm(goodEnterpriseService,enterpriceId);
    }

    @Override
    @RequestMapping("/upload")
    @ResponseBody
    @RequiresPermissions(value = "file_upload")
    public com.woniu.liuzhougov.common.utils.Result upload(MultipartFile file, HttpServletRequest request) throws IOException, IllegalStateException {
        return parentUpload(goodEnterpriseService,file,request);
    }

    @Override
    @RequestMapping("/addFile")
    @ResponseBody
    @RequiresPermissions(value = "file_upload")
    public com.woniu.liuzhougov.common.utils.Result addFile(RelatedInformation fileData) {
        return parentAddFile(fileData);
    }

}
